<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false">
        <el-container>
            <el-main>
                <el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right" style="height:450px;overflow:auto">
                    <!-- 打印条件 -->
                   <el-form-item label="是否打印公司名" prop="has_company">
                        <el-switch v-model="form.has_company" :active-value="1" :inactive-value="0"  disabled></el-switch>
                    </el-form-item>
                    <el-form-item label="是否打印客户名" prop="has_custom">
                        <el-switch v-model="form.has_custom" :active-value="1" :inactive-value="0"  disabled></el-switch>
                    </el-form-item>
                    <el-form-item label="是否打印成分" prop="has_component">
                        <el-switch v-model="form.has_component" :active-value="1" :inactive-value="0"  disabled></el-switch>
                    </el-form-item>
                    <el-form-item label="是否打印订单号" prop="has_orderno">
                        <el-switch v-model="form.has_orderno" :active-value="1" :inactive-value="0"  disabled></el-switch>
                    </el-form-item>
                    <!-- 订单明细 -->
                    <el-col :span="24">
                        <el-form-item label="订单明细" prop="size_data">
                            <sc-form-table ref="table" v-model="form.size_data" :addTemplate="addTemplate" placeholder="暂无数据" hideAdd hideDelete>
                                <el-table-column prop="size" label="尺码" width="100" align="center"></el-table-column>
                                <el-table-column prop="num" label="补打数量" align="center">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.num" placeholder="请输入补打数量"></el-input>
                                    </template>
                                </el-table-column>
                            </sc-form-table>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-main>
            <el-footer>
                <div style="display:flex;justify-content: end;">
                    <el-button @click="visible=false" >取消</el-button>
                    <el-button type="primary" :loading="isSaveing" @click="submit()">打印</el-button>
                </div>
            </el-footer>
        </el-container>
	</el-dialog>
    <print ref="pitDialog"></print>
</template>

<script>
import Print from '@/views/order/print.vue'
	export default {
        components:{Print},
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增委外合同单',
					edit: '补打条码',
					show: '查看'
				},
                dialog: {
				    pit: false,
			    },
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					contract_no_arr:"",
                    size_data:[], //辅料信息
                    has_company:"",
                    has_custom:"",
                    has_component:"",
                    has_orderno:"",
				},
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res  = [];
						res = await this.$API.produce.contract.repair.post(this.form);
						this.isSaveing = false;
						if(res.code == 1){
                            this.$refs.pitDialog.init(res.data);
                            this.visible = false;
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}else{
						return false;
					}
				})
			},
			//表单注入数据
			async setData(data){
                this.form.contract_no_arr = data.contract_no
                var res = await this.$API.all.printDef.get({client_id:data.client_id});
                this.form.has_company = res.data.has_company
                this.form.has_custom = res.data.has_custom
                this.form.has_component = res.data.has_component
                this.form.has_orderno = res.data.has_orderno
                let a = []
                data.orderDetail.map(item=>{
                    a.push({
                        size:item.goods_size
                    })
                })
                // 订单明细size_data
                this.form.size_data = a
			},
		}
	}
</script>

<style lang="scss"></style>
